<template>
  <el-main>
      <h3>共有<span style="color:red">{{count}}</span>条搜索结果</h3>
       <el-row>
    <el-col
      v-for="(elem, index) in filmList"
      :key="index"
      :offset="index &gt; 0 ? 1 : 0"
    >
      <el-card shadow="never" :body-style="{ padding: '0px' }">
        <img class="movieImg" :src="elem.filmPicture" />
        <div class="movie_sale">
          <router-link
            :to="{ name: 'cinema', query: { filmInfo: JSON.stringify(elem) } }"
            >购票</router-link
          >
        </div>
      </el-card>
    <!-- <div class="film_info">
        <div>电影名称：{{elem.filmName}}</div>
        <div>演员：{{elem.actorList}}</div>
    </div> -->
      <div class="movie_info">
        <div class="movie_title">{{elem.filmName}}</div>
        <div class="movie_score">{{elem.filmScore}}</div>
      </div>
    </el-col>
  </el-row>
  </el-main>
</template>

<script>
import getList from '../api/filmInfo'
export default {
    data(){
        return{
            count:0,
            query:{},
            filmList:[]
        }
    },
    created(){
        let search = this.$route.query
        if(Object.getOwnPropertyNames(this.$route.query).length != 0){
            this.query = search
        }

        this.getFilmList()

    },
     watch:{
      $route(to, from) {
             let search = this.$route.query
        if(Object.getOwnPropertyNames(this.$route.query).length != 0){
            this.query = search
        }
          this.getFilmList()
      }
  },
    methods:{
       getFilmList(){
          getList(this.query).then(res=>{
                if(res.code != 200){
      return this.$message.error(res.message)
    }
    else{
      this.count = res.data.value.length
      let temp = res.data.value
      console.log(temp);
      temp.forEach((element) => {
           let actorList = []
          element.actorList.forEach((element2) =>{
               actorList.push(element2.actorName);
          })
       element.actorList = actorList.join(",")
      });
      this.filmList = temp
    }
           })
           
        }
    }
}
</script>

<style lang="less" scoped>
.el-row{
    min-height: 285px;
    width: 1200px;
}
.el-col{
    margin-left: 20px;
}
.el-card {
  width: 200px;
  height: 332px;
  font-size: 0;
}
.movieImg {
  width: 100%;
  height: 286.1px;
}
.movie_info {
  width: 100%;
  color: #fff;
  position: absolute;
  bottom: 53px;
  overflow: hidden;
}
.movie_title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 10px;
  float: left;
}
.movie_score {
  color: #ffb400;
  float: right;
  margin-right: 7px;
}
.el-col {
  position: relative;
  width: 17%;
}
.coming_soon,.notice {
  margin-top: 20px;
}
.movie_sale {
  text-align: center;
  height: 46px;
  line-height: 46px;
  text-decoration: none;
  background: #fff;
  font-size: 16px;

  a {
    display: block;
    width: 100%;
    height: 100%;
    text-decoration: none;
  }
  a:hover {
    background-color: #ef4238;
    color: #fff;
  }
}
h3{
    margin-bottom:40px
}
.film_info{
    position: relative;
        left: 224px;
    top: -103px;
    div{
        margin-bottom: 10px;
    }
}
</style>